package com.springmvc.springbootOne.mapper;

import java.util.List;

import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;

import com.springmvc.springbootOne.util.Pagebean;


//mybatis映射 
@Mapper
public interface DemotestMapper {

	@SelectProvider(type = WhitsInformationMapperProvider.class, method = "getWhitsInformation")
	List<Map> getWhitsInformation(@Param("pg") Pagebean pg);

	@SelectProvider(type = WhitsInformationMapperProvider.class, method = "getWhitsInformationCount")
	int getWhitsInformationCount(@Param("pg") Pagebean pg);

	class WhitsInformationMapperProvider {
		public String getWhitsInformation(@Param("pg") Pagebean pg) {
			StringBuilder sql = new StringBuilder();
			sql.append("SELECT * FROM whits_information where 1=1 ");
			if (pg.getCondition().get("salesTel") != null) {
				sql.append(" and salesTel like '%" + pg.getCondition().get("salesTel") + "%'");
			}
			if (pg.getCondition().get("comName") != null) {
				sql.append(" and comName like '%" + pg.getCondition().get("comName") + "%'");
			}
			if (pg.getCondition().get("address") != null) {
				sql.append(" and address like '%" + pg.getCondition().get("address") + "%'");
			}
			sql.append(" limit #{pg.offset},#{pg.pagesize}");
			return sql.toString();
		}

		public String getWhitsInformationCount(@Param("pg") Pagebean pg) {
			StringBuilder sql = new StringBuilder("SELECT count(*) FROM whits_information where 1=1 ");
			if (pg.getCondition().get("salesTel") != null) {
				sql.append(" and salesTel like '%" + pg.getCondition().get("salesTel") + "%'");
			}
			if (pg.getCondition().get("comName") != null) {
				sql.append(" and comName like '%" + pg.getCondition().get("comName") + "%'");
			}
			if (pg.getCondition().get("address") != null) {
				sql.append(" and address like '%" + pg.getCondition().get("address") + "%'");
			}
			return sql.toString();
		}
	}

	
}
